import request from '@/utils/request';
/* 商品分类管理 */
export const categoryList = params => request({
  url: '/v1/category',
  method: 'GET',
  params
}).then(({ data }) => {
  return data;
}); // 分类列表
export const addCategory = params => request({
  url: '/v1/category',
  method: 'POST',
  params
}).then(res => {
  return res;
}); // 添加分类
export const categoryDetail = ({ id }) => request({
  url: `/v1/category/${id}`,
  method: 'GET'
}).then(({ data }) => {
  return data;
}); // 添加分类
export const editCategory = params => request({
  url: `/v1/category/${params.id}`,
  method: 'PUT',
  data: params
}).then(res => {
  return res;
}); // 编辑分类
export const deleteCategory = params => request({
  url: `/v1/category/${params.id}`,
  method: 'DELETE',
  data: params
}).then(res => {
  return res;
}); // 编辑分类
export const sortCategory = params => request({
  url: '/v1/category/sort',
  method: 'PUT',
  data: params
}).then(res => {
  return res;
}); // 批量修改分类排序

/* 商品规格管理 */
export const unitList = params => request({
  url: '/v1/goods_attrs',
  method: 'GET',
  params
}).then(({ data }) => {
  return data;
}); // 商品规格列表
export const addUnit = params => request({
  url: '/v1/goods_attrs',
  method: 'POST',
  data: params
}).then(res => {
  return res;
}); // 添加商品规格
export const unitDetail = ({ id }) => request({
  url: `/v1/goods_attrs/${id}`,
  method: 'GET'
}).then(({ data }) => {
  return data;
}); // 商品规格详情
export const editUnit = params => request({
  url: '/v1/goods_attrs',
  method: 'PUT',
  data: params
}).then(res => {
  return res;
}); // 编辑商品规格
export const deleteUnit = ({ id }) => request({
  url: `/v1/goods_attrs/${id}`,
  method: 'DELETE'
}).then(({ msg }) => {
  return msg;
}); // 删除商品规格
export const unitAll = () => request({
  url: '/v1/goods_attrs/all',
  method: 'GET'
}).then(({ data }) => {
  return data;
}); // 全量商品规格

/* 商品管理 */
export const goodsList = params => request({
  url: '/v1/goods',
  method: 'GET',
  params
}).then(({ data }) => {
  return data;
}); // 商品管理列表
export const goodsInfo = ({ id }) => request({
  url: `/v1/goods/${id}`,
  method: 'GET'
}).then(({ data }) => {
  return data;
}); // 商品详情
export const addGoods = params => request({
  url: '/v1/goods',
  method: 'POST',
  data: params
}).then(res => {
  return res;
}); // 添加商品
export const editGoods = params => request({
  url: `/v1/goods/${params.id}`,
  method: 'PUT',
  data: params
}).then(res => {
  return res;
}); // 编辑商品
